/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-03-08 14:42:08
 * @LastEditors: huangtianyang
 * @LastEditTime: 2024-05-08 11:03:03
 * @FilePath: \report-h5\src\pages\vehicleCondition\query\index.ts
 */
import { onUnmounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { BasicData } from '@/utils/basicData'
import QueryReportStatus from '@/utils/queryReportStatus'

export class ReportQuery extends BasicData {
    //
    homeBtnVisible = ref(false)
    //vin
    vin = ref('')
    //订单id
    orderId = ref('')
    //订单号
    orderNo = ref('')
    //车牌颜色
    licensePlateColor = ref('')
    //报告类型 1//出险 2//维修版
    reportType = ref(0)
    //默认查询成功
    queryStatus = ref(true)
    vinParseId = ref('')
    reportId = ref('')
    timer: any
    constructor() {
        super()
        const _router = useRoute()
        this.vin.value = _router.query.vin as string
        this.orderId.value = _router.query.orderId as string
        this.orderNo.value = _router.query.orderNo as string
        this.licensePlateColor.value = _router.query.licensePlateColor as string
        this.reportType.value = Number(_router.query.reportType as string)
        this.vinParseId.value = _router.query.vinParseId as string
        this.reportId.value = _router.query.reportId as string

        const queryReport = new QueryReportStatus()

        queryReport.query({
            vin: this.vin.value,
            orderNo: this.orderNo.value,
            vinParseId: this.vinParseId.value,
            reportType: Number(this.reportType.value),
            isSkip: true,
            skipMode: 'replace',
            loop: true,
            reportId: this.reportId.value,
            succeed: () => {},
            failed: () => {
                //
                this.queryStatus.value = false
            }
        })

        onUnmounted(() => {
            if (queryReport.timer) {
                clearTimeout(queryReport.timer)
            }
        })
    }
    //返回首页
    onOpenHome = () => {
        this.router.replace('/index')
    }
    //刷新
    onRefresh = () => {
        this.router.go(0)
    }
}
